#include "Camera.h"
#include "Constants.h"
#include "Input.h"
#include "Game.h"

Camera::Camera() {

};

Camera::~Camera() {

}

int Camera::Initialize() {

	this->x = 0.0f;
	this->y = 0.0f;
	this->z = 10.0f;

	this->lookatX = this->x;
	this->lookatY = this->y;
	this->lookatZ = 0.0f;

	this->xVel = 0.0f;
	this->yVel = 0.0f;
	this->zVel = 0.0f;

	this->followEntityId = -1;

	return 0;
}

void Camera::HandleInput() {
	if(this->followEntityId < 0) {
		if(Game::InputPtr->KeysPressed.num2) {
			if(this->yVel > -5.0f) this->yVel -= 0.05f;
			else this->yVel = -5.0f;
		}
			
		if(Game::InputPtr->KeysPressed.num4) {
			if(this->xVel > -5.0f) this->xVel -= 0.05f;
			else this->xVel = -5.0f;
		}

		if(Game::InputPtr->KeysPressed.num6) {
			if(this->xVel < 5.0f) this->xVel += 0.05f;
			else this->xVel = 5.0f;
		}
	
		if(Game::InputPtr->KeysPressed.num8) {
			if(this->yVel < 5.0f) this->yVel += 0.05f;
			else this->yVel = 5.0f;
		}
	
		if(!Game::InputPtr->KeysPressed.num4 && !Game::InputPtr->KeysPressed.num6) {
			if(this->xVel < -0.1f) this->xVel += 0.08f;
			if(this->xVel > 0.1f) this->xVel -= 0.08f;
			if(this->xVel >= -0.1f && this->xVel <= 0.1f) this->xVel = 0.0f;
		}
	
		if(!Game::InputPtr->KeysPressed.num2 && !Game::InputPtr->KeysPressed.num8) {
			if(this->yVel < -0.1f) this->yVel += 0.08f;
			if(this->yVel > 0.1f) this->yVel -= 0.08f;
			if(this->yVel >= -0.1f && this->yVel <= 0.1f) this->yVel = 0.0f;
		}
	
		if(Game::InputPtr->KeysPressed.numplus) {
			if(this->zVel < 5.0f) this->zVel += 0.05f;
			else this->zVel = 5.0f;
		}
	
		if(Game::InputPtr->KeysPressed.numminus) {
			if(this->zVel > -5.0f) this->zVel -= 0.05f;
			else this->zVel = -5.0f;
		}
	
		if(!Game::InputPtr->KeysPressed.numplus && ! Game::InputPtr->KeysPressed.numminus) {
			if(this->zVel < -0.1f) this->zVel += 0.08f;
			if(this->zVel > 0.1f) this->zVel -= 0.08f;
			if(this->zVel >= -0.1f && this->zVel <= 0.1f) this->zVel = 0.0f;
		}
	}
}
	
void Camera::UpdatePosition() {
	this->x += this->xVel / (float)ticksPS;
	this->y += this->yVel / (float)ticksPS;
	this->z += this->zVel / (float)ticksPS;

	this->lookatX = this->x;
	this->lookatY = this->y;
	this->lookatZ = 0.0f;
}